package com.colin.aiyi.ui;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.TextView;

import com.colin.aiyi.R;
import com.colin.aiyi.entity.User;
import com.colin.aiyi.ui.Home.MainActivity;
import com.colin.aiyi.utils.SharePreferenceUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by hl on 2017/5/31.
 */

public class SettingAc extends BaseActivity {


    @BindView(R.id.text_banner_left)
    TextView textBannerLeft;
    @BindView(R.id.text_banner_title)
    TextView textBannerTitle;
    @BindView(R.id.text_banner_rigth)
    TextView textBannerRigth;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ac_setting);
        ButterKnife.bind(this);
        user=getUser();
        textBannerTitle.setText("设置");
        textBannerLeft.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
//        if (!isLoginWithLogin(user)){
//            return;
//        }
        switch (v.getId()) {
            case R.id.text_passwd:
                if (isLoginWithLogin(user)){
                    startActivity(new Intent(this, EditPasswdAc.class));
                }
                break;
            case R.id.text_reply:
                if (isLoginWithLogin(user)){
                    startActivity(new Intent(this, FeedbackAc.class));
                }
                break;
            case R.id.button_send:
//                SharePreferenceUtil.removeObject(this, User.class);
//                Intent intent=new Intent(this,MainActivity.class);
//                intent.putExtra("isClose",1);
//                setResult(0x4444,intent);
//                finish();
                showDialog();
                break;
        }
    }

    public void showDialog(){
        new AlertDialog.Builder(this)
                .setTitle("确认退出当前帐号吗？")
                .setIcon(R.mipmap.app_logo)
                .setPositiveButton("退出", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        SharePreferenceUtil.removeObject(SettingAc.this, User.class);
                        SharePreferenceUtil.saveObject(SettingAc.this, new User());
//                        Intent intent=new Intent(SettingAc.this,MainActivity.class);
//                        intent.putExtra("isClose",1);
//                        setResult(0x4444,intent);
//                        finish();
                        Intent intent = new Intent(SettingAc.this, MainActivity.class);
                        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(intent);
                        finish();

                    }
                })
                .setNegativeButton("返回",null).show();
    }
}
